import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

main(List<String> args) {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: Text('RenderObject'),
      ),
      body: Container(
        color: Colors.orange[100],
        child: ShadowBox(
          child: FlutterLogo(
            size: 50,
          ),
        ),
      ),
    ),
  ));
}

class ShadowBox extends SingleChildRenderObjectWidget {
  ShadowBox({required Widget child}) : super(child: child);

  @override
  RenderObject createRenderObject(BuildContext context) {
    return RenderShadowBox();
  }
}

class RenderShadowBox extends RenderProxyBox {
  // 布局，如果没有特别的要求可以不用重写
  // @override
  // void performLayout() {
  //   child.layout(constraints, parentUsesSize: true);
  //   size = child.size;
  // }

  // 绘制，
  @override
  void paint(PaintingContext context, Offset offset) {
    context.paintChild(child!, offset);
    // 绘制新图层，这是透明度
    context.pushOpacity(offset, 127, (context, offset) {
      context.paintChild(child!, offset + Offset(30, 30));
    });
  }
}
